const redis = require("redis");
const client = redis.createClient();

client.on("error", function(error) {
  console.error(error);
});

client.syncSet = function (key, value) {
    return new Promise((resolve, reject) => {
        client.set(key, value, function (err, res) {
            if (err) {
                console.log('get error:', err)
                resolve(false)
            } else {
                console.log('get success: ', res)
                resolve(res)
            }
        });
    })
}

client.syncGet = function (key) {
    return new Promise((resolve, reject) => {
        client.get(key, function (err, res) {
            if (err) {
                console.log('get error:', err)
                reject(err)
            } else {
                console.log('get success: ', res)
                resolve(res)
            }
        });
    })
}
// client.syncGet('SD1637560276064')

module.exports = client